package com.glodon.paas.account.dao;

import java.lang.reflect.Method;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.ThrowsAdvice; 

import com.glodon.paas.exception.PaasServerException;
import com.glodon.paas.exception.PaasServerExceptionFactory;

public class DaoExceptionAspect implements ThrowsAdvice{
	private static Logger LOGGER = LoggerFactory.getLogger(DaoExceptionAspect.class);


	public void afterThrowing(Method m, Object[] args, Object target, Exception ex) throws Exception {
		if(ex instanceof PaasServerException){
			LOGGER.error(ex.getMessage());
			throw ex;
		}else{
			PaasServerException e =  PaasServerExceptionFactory.dbException(m.getName(), ex);
			LOGGER.error(e.getMessage());
			throw e;
		}		
    } 
}
